import service from '@/utils/request'
import { useUserStore } from '@/pinia/modules/user'
const userStore = useUserStore()

//获取总地块面积
export const getFarmCount = (data) => {
  return new Promise((resolve, reject) => {
    service.post('/boss/farm/farm-count', data)
      .then(res => {
        resolve(res.data)
      })
  })
}
// 农场列表,要求展示作物，就用该接口
export const getFarmList = (data) => {
  return new Promise((resolve, reject) => {
    // roleId=1为平台管理员
    if (!data.companyId) {
      const companyId = userStore.userInfo.roleId == 1 ? null : userStore.userInfo.companyId
      data.companyId = companyId
    }

    service.post('/boss/farm/farm-list', data)
      .then(res => {
        resolve(res.data)
      })
  })
}
// 农场列表-不含作物信息（没要求展示作物，就用该接口）
export const getFarmList2 = (data) => {
  return new Promise((resolve, reject) => {
    // roleId=1为平台管理员
    if (!data.companyId) {
      const companyId = userStore.userInfo.roleId == 1 ? null : userStore.userInfo.companyId
      data.companyId = companyId
    }

    service.post('/boss/farm/farm-list-nocrop', data)
      .then(res => {
        resolve(res.data)
      })
  })
}


//地块管理-分页列表查询
export const getLandList = (data) => {
  return new Promise((resolve, reject) => {
    service.get('/lngis/farm/farm-land/land-pageList', {
      params:data,
      withCredentials: true
    }).then(res => {
        resolve(res.data)
      })
  })
}

//地块管理-分页列表查询-地图地块
export const getLandMapList = (data) => {
  return new Promise((resolve, reject) => {
    service.get('/lngis/farm/farm-land/land-data', {
      params:data,
      withCredentials: true
    }).then(res => {
        resolve(res.data)
      })
  })
}

//地块管理-select地块类型
export const getLandTypeList = (data) => {
  return new Promise((resolve, reject) => {
    service.post('/boss/tanc-farm-land-type/tanc-farm-land-type-list',data).then(res => {
        resolve(res.data)
      })
  })
}


//地块管理-select作物类型
export const getCropList = (data) => {
  return new Promise((resolve, reject) => {
    service.post('/boss/crop/tanc-crop-list',data).then(res => {
        resolve(res.data)
      })
  })
}

//地块管理-解除地块关系(BOSS)
export const releaseFarmland = (data) => {
  return new Promise((resolve, reject) => {
    service.post('/boss/tanc-farm-land/release-farmland',data).then(res => {
        resolve(res.data)
      })
  })
}
//根据经纬度综合显示待认领、已认领、被认领地块信息(BOSS)
export const getCompositeFarmland = (data) => {
  return new Promise((resolve, reject) => {
    service.get('/boss/tanc-farm-land/composite-farmland',{params:data}).then(res => {
        resolve(res.data)
      })
  })
}
//地块管理-地块申诉(BOSS)
export const claimLand = (data) => {
  return new Promise((resolve, reject) => {
    service.post('/boss/tanc-farm-land-ownership-claim/tanc-farm-land-ownership-claim-add',data).then(res => {
        resolve(res.data)
      })
  })
}
//地块管理-认领
export const tancLand = (data) => {
  return new Promise((resolve, reject) => {
    service.post('/boss/tanc-farm-land/tanc-farm-land-claim',data).then(res => {
        resolve(res.data)
      })
  })
}


//地块管理-地块申诉(BOSS)
export const uploadFile = (data) => {
  return new Promise((resolve, reject) => {
    service.post('/lngis/farm/other-farm-land/upload-land-source-pic',data).then(res => {
        resolve(res.data)
      })
  })
}


//地块管理-土壤养分
export const getCompositionList = (data) => {
  return new Promise((resolve, reject) => {
    service.post('/boss/farmland-composition/composition-list',data).then(res => {
        resolve(res.data)
      })
  })
}
//地块管理-土壤养分-导入编辑列表
export const getFarmlandCompositionList = (data) => {
  return new Promise((resolve, reject) => {
    service.post('/boss/farmland-composition/farmland-composition-list',data).then(res => {
        resolve(res.data)
      })
  })
}


//地块管理-土壤养分-标准列表
export const getCompositionStandardList = (data) => {
  return new Promise((resolve, reject) => {
    service.get('/boss/farmland-composition/composition-standard-list',{params:data}).then(res => {
        resolve(res.data)
      })
  })
}


//地块管理-土壤养分-下载模板
export const downTemplate = (data) => {
  return new Promise((resolve, reject) => {
    service.get('/boss/farmland-composition/template-file',{params:data,responseType: 'blob'}).then(res => {
        resolve(res.data)
      })
  })
}
//地块管理-导入土壤养分
export const importComposition = (data) => {
  return new Promise((resolve, reject) => {
    service.post('/boss/farmland-composition/import-farmland-composition',data).then(res => {
        resolve(res.data)
      })
  })
}


//地块管理-删除土壤养分
export const deleteComposition = (data) => {
  return new Promise((resolve, reject) => {
    service.post('/boss/tanc-farm-land-composition-log/tanc-farm-land-composition-log-delete',data).then(res => {
        resolve(res.data)
      })
  })
}

//地块管理-新增土壤养分
export const saveComposition = (data) => {
  return new Promise((resolve, reject) => {
    service.post('/boss/farmland-composition/farmland-composition-save',data).then(res => {
        resolve(res.data)
      })
  })
}

//地块管理-编辑土壤养分
export const editComposition = (data) => {
  return new Promise((resolve, reject) => {
    service.post('/boss/farmland-composition/farmland-composition-edit',data).then(res => {
        resolve(res.data)
      })
  })
}

export const delComposition = (data) => {
  return new Promise((resolve, reject) => {
    service.post('/boss/farmland-composition/farmland-composition-delete', data)
      .then(res => {
        resolve(res.data)
      })
  })
}

//QQ地图行政区
export const getDistrictList = (data) => {
  return new Promise((resolve, reject) => {
    service.get('/boss/notify/district',{params:data}).then(res => {
        resolve(res.data)
      })
  })
}

//获取未被占用地块
export const getFarmLandsList = (data) => {
  return new Promise((resolve, reject) => {
    service.get('/boss/tanc-farm-land/farmland-ids-fspp',{params:data}).then(res => {
        resolve(res.data)
      })
  })
}

//超级小min地块列表
export const getLandMicroMiniList = (data) => {
  return new Promise((resolve, reject) => {
    service.post('/boss/tanc-farm-land/tanc-farm-land-micro-mini-list', data)
      .then(res => {
        resolve(res.data)
      })
  })
}

//超级小地块列表
export const getLandMiniList = (data) => {
  return new Promise((resolve, reject) => {
    service.post('/boss/tanc-farm-land/tanc-farm-land-mini-list', data)
      .then(res => {
        resolve(res.data)
      })
  })
}
